#include "commands.h"
#include <QtGui>

MoveCommand::MoveCommand(ImageItem *imageItem, const QPointF &oldPos,
                 QUndoCommand *parent)
    : QUndoCommand(parent)
{
    m_imageItem = imageItem;
    m_newPos = imageItem->pos();
    m_oldPos = oldPos;
}

void MoveCommand::undo()
{
    m_imageItem->setPos(m_oldPos);
    m_imageItem->scene()->update();
    setText(QObject::tr("Move picture."));
}

void MoveCommand::redo()
{
    m_imageItem->setPos(m_newPos);
    setText(QObject::tr("Move picture."));
}

ImageCommand::ImageCommand(ImageItem *imageItem, const QImage &newPixmap, QString operatorStr,
                           QUndoCommand *parent)
    : QUndoCommand(parent)
{
    m_imageItem = imageItem;
    m_oldPixmap = imageItem->pixmap().toImage();
    m_newPixmap = newPixmap;
    m_operatorStr = operatorStr;
}

void ImageCommand::undo()
{
    m_imageItem->setPixmap(QPixmap::fromImage(m_oldPixmap));
    setText(m_operatorStr);
}

void ImageCommand::redo()
{
    m_imageItem->setPixmap(QPixmap::fromImage(m_newPixmap));
    setText(m_operatorStr);
}
